package pe.com.certicom.moviles.model.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import pe.com.certicom.moviles.model.beans.DetallePeriodoFacturacion;
import pe.com.certicom.moviles.model.beans.DetallePeriodoFacturacionExample;
import pe.com.certicom.moviles.model.beans.DetallePeriodoFacturacionKey;

import com.ibatis.sqlmap.client.SqlMapClient;


@Repository
public class DetallePeriodoFacturacionDAOImpl extends SqlMapClientDaoSupport implements DetallePeriodoFacturacionDAO {

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public DetallePeriodoFacturacionDAOImpl() {
		super();
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public int countByExample(DetallePeriodoFacturacionExample example) {
		Integer count = (Integer) getSqlMapClientTemplate().queryForObject(
				"detalle_periodo_facturacion.ibatorgenerated_countByExample",
				example);
		return count;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public int deleteByExample(DetallePeriodoFacturacionExample example) {
		int rows = getSqlMapClientTemplate().delete(
				"detalle_periodo_facturacion.ibatorgenerated_deleteByExample",
				example);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public int deleteByPrimaryKey(DetallePeriodoFacturacionKey key) {
		int rows = getSqlMapClientTemplate()
				.delete("detalle_periodo_facturacion.ibatorgenerated_deleteByPrimaryKey",
						key);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public void insert(DetallePeriodoFacturacion record) {
		getSqlMapClientTemplate().insert(
				"detalle_periodo_facturacion.ibatorgenerated_insert", record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public void insertSelective(DetallePeriodoFacturacion record) {
		getSqlMapClientTemplate().insert(
				"detalle_periodo_facturacion.ibatorgenerated_insertSelective",
				record);
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	@SuppressWarnings("unchecked")
	public List<DetallePeriodoFacturacion> selectByExample(
			DetallePeriodoFacturacionExample example) {
		List<DetallePeriodoFacturacion> list = getSqlMapClientTemplate()
				.queryForList(
						"detalle_periodo_facturacion.ibatorgenerated_selectByExample",
						example);
		return list;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public DetallePeriodoFacturacion selectByPrimaryKey(
			DetallePeriodoFacturacionKey key) {
		DetallePeriodoFacturacion record = (DetallePeriodoFacturacion) getSqlMapClientTemplate()
				.queryForObject(
						"detalle_periodo_facturacion.ibatorgenerated_selectByPrimaryKey",
						key);
		return record;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public int updateByExampleSelective(DetallePeriodoFacturacion record,
			DetallePeriodoFacturacionExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate()
				.update("detalle_periodo_facturacion.ibatorgenerated_updateByExampleSelective",
						parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public int updateByExample(DetallePeriodoFacturacion record,
			DetallePeriodoFacturacionExample example) {
		UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
		int rows = getSqlMapClientTemplate().update(
				"detalle_periodo_facturacion.ibatorgenerated_updateByExample",
				parms);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public int updateByPrimaryKeySelective(DetallePeriodoFacturacion record) {
		int rows = getSqlMapClientTemplate()
				.update("detalle_periodo_facturacion.ibatorgenerated_updateByPrimaryKeySelective",
						record);
		return rows;
	}

	/**
	 * This method was generated by Apache iBATIS ibator. This method corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	public int updateByPrimaryKey(DetallePeriodoFacturacion record) {
		int rows = getSqlMapClientTemplate()
				.update("detalle_periodo_facturacion.ibatorgenerated_updateByPrimaryKey",
						record);
		return rows;
	}

	/**
	 * This class was generated by Apache iBATIS ibator. This class corresponds to the database table detalle_periodo_facturacion
	 * @ibatorgenerated  Sun Nov 10 16:52:19 COT 2013
	 */
	private static class UpdateByExampleParms extends
			DetallePeriodoFacturacionExample {
		private Object record;

		public UpdateByExampleParms(Object record,
				DetallePeriodoFacturacionExample example) {
			super(example);
			this.record = record;
		}

		public Object getRecord() {
			return record;
		}
	}

	@Autowired
	public void createSqlMapClient(SqlMapClient sqlMapClient){
	   setSqlMapClient(sqlMapClient);
	}

	@Override
	public long selectMaxDetalle(DetallePeriodoFacturacion record) {
		// TODO Auto-generated method stub
		Long max = (Long) getSqlMapClientTemplate().queryForObject(
				"detalle_periodo_facturacion.selectMaxDetalle",record);
		//Si no hay registros para el periodo y proveedor retornamos cero.
		if(max==null)return 0L;
		else return max;
	}
}